package com.lixiaofeng.paintstudy;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by lanouhn on 16/8/18.
 */
public class CustomView extends View {
    /**
     * 实现了这个构造方法，我们就可以在布局文件中通过标签的形式引入控件或者View
     *
     * @param context
     * @param attrs
     */
    public CustomView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    /**
     * 满足我们在代码当中通过new的形式来创建控件或者View
     *
     * @param context
     */
    public CustomView(Context context) {
        super(context);
    }

    /**
     * 通过这个方法，我们可以获取到画布，该方法在创建这个视图的时候会调用，画出该方法中所有的图形
     *
     * @param canvas
     */
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //改变整个画布的颜色
        canvas.drawColor(Color.WHITE);
        //创建一个画笔
        Paint paint = new Paint();
        //抗锯齿
        paint.setAntiAlias(true);
        //设置画笔颜色
        paint.setColor(Color.BLUE);
        //设置画笔粗细
        paint.setStrokeWidth(10);
        //设置是空心或者实心
        paint.setStyle(Paint.Style.STROKE);
        //绘制一个空心圆
//        canvas.drawCircle(80, 80, 80, paint);
//        //绘制一个矩形
//        canvas.drawRect(80, 160, 300, 300, paint);
//        //绘制一个正方形
//        canvas.drawRect(120, 300, 220, 400, paint);
//        //绘制一个圆角矩形
//        RectF fectF = new RectF(10, 400, 500, 600);
//        canvas.drawRoundRect(fectF, 100, 100, paint);
        //绘制奥运五环
        //绘制蓝环
        Paint blue_paint = new Paint();
        blue_paint.setColor(Color.BLUE);
        blue_paint.setStrokeWidth(10);
        blue_paint.setStyle(Paint.Style.STROKE);
        blue_paint.setAntiAlias(true);

        canvas.drawCircle(110, 150, 60, blue_paint);

        //绘制黑环

        Paint black_paint = new Paint();
        black_paint.setColor(Color.BLACK);
        black_paint.setStrokeWidth(10);
        black_paint.setStyle(Paint.Style.STROKE);
        black_paint.setAntiAlias(true);

        canvas.drawCircle(245, 150, 60, black_paint);
        //绘制红环
        Paint red_paint = new Paint();
        red_paint.setColor(Color.RED);
        red_paint.setStrokeWidth(10);
        red_paint.setStyle(Paint.Style.STROKE);
        red_paint.setAntiAlias(true);

        canvas.drawCircle(380, 150, 60, red_paint);


        //绘制黄环

        Paint yellow_paint = new Paint();
        yellow_paint.setColor(Color.YELLOW);
        yellow_paint.setStrokeWidth(10);
        yellow_paint.setStyle(Paint.Style.STROKE);
        yellow_paint.setAntiAlias(true);

        canvas.drawCircle(175.5f, 210, 60, yellow_paint);


        //绘制绿环
        Paint green_paint = new Paint();
        green_paint.setColor(Color.GREEN);
        green_paint.setStrokeWidth(10);
        green_paint.setStyle(Paint.Style.STROKE);
        green_paint.setAntiAlias(true);

        canvas.drawCircle(310, 210, 60, green_paint);


    }
}
